package com.teamcenter.rac.massupdate.validators;

import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.massupdate.Activator;
import com.teamcenter.rac.massupdate.ui.Messages;
import com.teamcenter.rac.massupdate.utils.SourceHelper;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.views.properties.IPropertySource;

public class MarkupValidator
  extends AbstractMassUpdateValidator
{
  public IStatus validate(Object paramObject)
  {
    if (paramObject == null) {
      return new Status(4, Activator.getDefault().getBundleSymbolicName(), Messages.Validator_InputIsNotSet);
    }
    if ((paramObject instanceof IPropertySource))
    {
      IPropertySource localIPropertySource = (IPropertySource)paramObject;
      TCComponent localTCComponent = SourceHelper.getAssociatedComponent(localIPropertySource, getTCSession());
      if (localTCComponent.getType().equals("Fnd0Markup"))
      {
        boolean bool = false;
        try
        {
          bool = localTCComponent.okToModify();
        }
        catch (TCException localTCException)
        {
          Logger.getLogger(MarkupValidator.class).error(localTCException.getLocalizedMessage(), localTCException);
        }
        if (!bool) {
          return new Status(1, Activator.getDefault().getBundleSymbolicName(), Messages.Validator_MarkupNotModifiable);
        }
        return Status.OK_STATUS;
      }
      return new Status(4, Activator.getDefault().getBundleSymbolicName(), Messages.Validator_InputNotAMarkup);
    }
    return Status.OK_STATUS;
  }
}